/**
 * ${tableComment} 修改
 *
 * @author motorfu
 * @email ffu@maxleap.com
 * @since ${date}
 */
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import {
  Drawer, Form, message
} from 'antd';
import { ${moduleName}Form } from "../index";
import DrawerFooter from "../../../../common-module/components/DrawerFooter";

class Edit${moduleName}Modal extends React.Component {

  handleSubmit = (e) => {
    e.preventDefault();
    const {itemData, form, onModify, onClose} = this.props;
    form.validateFieldsAndScroll((err, values) => {
          if (!err) {
            values.id = itemData.id;
            onModify(values, response => {
              if (response.code === 200) {
                form.resetFields()
                onClose({refresh: true});
              } else {
                message.error(response.msg);
              }
            });
            console.log('Received values of form: ', values);
          }
        }
    );
  }

  render() {
    const {itemData, visible, onClose} = this.props;
    return (
        <Drawer title="编辑${tableComment}"
                visible={visible}
                maskClosable={false}
                onClose={onClose}
                width={720}
        >
          <${moduleName}Form {...this.props}/>
          <DrawerFooter onClose={onClose}
                        handleSubmit={this.handleSubmit}
                        loading={this.props.modifyLoading}
          />
        </Drawer>
    );
  }

}

Edit${moduleName}Modal.propTypes = {
  itemData: PropTypes.object.isRequired,
  visible: PropTypes.bool.isRequired,
  onModify: PropTypes.func.isRequired,
  onClose: PropTypes.func.isRequired
};
export default connect(state => {
  return {
    modifyLoading: state.${module}.${moduleName?lower_case}.modifyLoading
  };
})(Form.create()(Edit${moduleName}Modal));